package it.fc.action;

import fc.utils.HibernateUtil;
import it.fc.bean.UserBean;
import it.fc.service.impl.IServiceImpl;
import it.fc.service.interfaces.IDbService;
import it.fc.service.interfaces.IService;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.opensymphony.xwork2.ActionSupport;

/*main class*/

@SuppressWarnings("rawtypes")
public class FcAction extends ActionSupport implements SessionAware {
    private static final long serialVersionUID = -1976597186624657897L;
    private static Logger     log              = Logger.getLogger(FcAction.class);
    private Map               session          = null;
    private static IService   services         = null;

    public FcAction() {
        if (getServices() == null) {
            log.debug("--------------------Init FC ACTION-----------------------");
            setServices(new IServiceImpl());
            log.debug("Creating Services................");
        }
    }

    @Override
    public String execute() throws Exception {

        return SUCCESS;
    }

    @SuppressWarnings("rawtypes")
    public Map getSession() {
        return this.session;
    }

    @SuppressWarnings("rawtypes")
    public void setSession(Map session) {
        this.session = session;
    }

    protected int getIdUser() {
        if (getSession().get("user") != null) {
            return ((UserBean) getSession().get("user")).getIdUser();
        } else {
            return 0;
        }
    }

    protected UserBean getUser() {
        if (getSession().get("user") != null) {
            return ((UserBean) getSession().get("user"));
        } else {
            return null;
        }
    }

    public void setServices(IService services) {
        this.services = services;
    }

    public IService getServices() {
        return services;
    }

    /*services*/

    public IDbService getDbService() {
        return (IDbService) getServices().getService(IService.DBSERVICE);
    }

}
